package com.vm.activity;

import com.wwtscapp.apk.R;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;


@SuppressLint("InflateParams")
public class CommentDialog extends AlertDialog {
	private Context context;
	private ClickListenerInterface clickListenerInterface;

	protected CommentDialog(Context context) {
		super(context, R.style.dialog);
		// TODO Auto-generated constructor stub
		this.context = context;
	}

	public interface ClickListenerInterface {
		public void doConfirm();

		public void doCancel();
	}

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		init();
	}

	public void init() {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.published_comments, null);
		setContentView(view);
		Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
		Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
		btn_confirm.setOnClickListener(new clickListener());
		btn_cancel.setOnClickListener(new clickListener());
		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
		lp.dimAmount = 0.5f;
		lp.width = (int) (d.widthPixels * 0.8);
		lp.height = 520;
		dialogWindow.setAttributes(lp);
	}

	private class clickListener implements View.OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			int id = v.getId();
			switch (id) {
			case R.id.btn_confirm:
				clickListenerInterface.doConfirm();
				break;
			case R.id.btn_cancel:
				clickListenerInterface.doCancel();
				break;
			default:
				break;
			}
		}
	};

}